Skip to content

[Spring] Make ServiceBus JMS connection factory creation customizable#49676

Open
rujche wants to merge 8 commits into
mainfrom
rujche/main/Make-it-possible-to-inject-desired-subclass-of-ServiceBusJmsConnectionFactory-into-the-configuration
Open

[Spring] Make ServiceBus JMS connection factory creation customizable#49676
rujche wants to merge 8 commits into
mainfrom
rujche/main/Make-it-possible-to-inject-desired-subclass-of-ServiceBusJmsConnectionFactory-into-the-configuration

Conversation

@rujche

@rujche rujche commented Jun 30, 2026

Copy link
Copy Markdown
Member

Description

This PR implements the feature request from #45942 by adopting the old PR #46052 approach for connection-factory creation customization.

What changed

  • Added AzureServiceBusJmsConnectionFactoryFactory as a public extension interface.
  • Added a default @ConditionalOnMissingBean implementation in Service Bus JMS auto-configuration.
  • Updated internal ServiceBusJmsConnectionFactoryFactory to use the new extension interface.
  • Updated ServiceBusJmsConnectionFactoryConfiguration to obtain and use the factory bean.
  • Updated ServiceBusJmsContainerConfiguration to also use the same factory bean extension point, so listener-container paths honor custom factories too.
  • Optimized default passwordless factory initialization by creating the TokenCredentialProvider once at bean creation time and reusing it for factory invocations.
  • Added/updated tests covering service-bus, caching, pooling and passwordless scenarios with custom factory creation.
  • Updated changelog only in sdk/spring/CHANGELOG.md (with PR reference).

Old PR comment resolution

  • Followed the preferred design discussion by using an instance-factory extension point (AzureServiceBusJmsConnectionFactoryFactory).
  • Avoided module-level changelog noise by keeping the change only in top-level spring changelog.
  • Addressed review follow-ups:
    • Routed shared helper/call paths through bean-based extension point.
    • Added fail-fast null checks for custom factory bean behavior.
    • Fixed line-length and style issues to satisfy Checkstyle.
    • Fixed JavaDoc formatting/indentation for the new helper method parameter documentation.

Verification

  • mvn -pl sdk/spring/spring-cloud-azure-autoconfigure -Dtest=ServiceBusJmsConnectionFactoryConfigurationTests test -DskipITs -Dspotbugs.skip=true -Dcheckstyle.skip=true
  • mvn -pl sdk/spring/spring-cloud-azure-autoconfigure -DskipTests checkstyle:check

Fixes #45942

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a Spring Boot extension point that lets applications customize how ServiceBusJmsConnectionFactory instances are created (including using custom subclasses), and wires that extension point through the Service Bus JMS auto-configuration with updated test coverage.

Changes:

  • Introduces a new public functional interface, AzureServiceBusJmsConnectionFactoryFactory, for pluggable ServiceBusJmsConnectionFactory creation.
  • Adds a default @ConditionalOnMissingBean implementation of the factory in ServiceBusJmsAutoConfiguration and updates internal wiring to obtain and use the factory bean.
  • Expands tests to cover custom factory creation across direct, caching, pooling, and passwordless scenarios; updates sdk/spring/CHANGELOG.md.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/jms/ServiceBusJmsConnectionFactoryConfigurationTests.java Adds tests and a custom subclass + factory bean to validate the new customization hook across scenarios.
sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/jms/AzureServiceBusJmsConnectionFactoryFactory.java New public extension interface for user-provided connection factory creation.
sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/jms/ServiceBusJmsConnectionFactoryFactory.java Refactors internal factory creation to use the new instance-factory extension point.
sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/jms/ServiceBusJmsConnectionFactoryConfiguration.java Updates auto-configured sender ConnectionFactory registration to obtain and use the factory bean (while retaining a static helper).
sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/jms/ServiceBusJmsAutoConfiguration.java Adds a default AzureServiceBusJmsConnectionFactoryFactory bean when one is not supplied by the application.
sdk/spring/CHANGELOG.md Documents the newly added extension point in the top-level Spring changelog.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/jms/ServiceBusJmsContainerConfiguration.java:76

  • There is trailing whitespace on the blank line between field declarations and the following comment. This can trip whitespace/style checks and creates noisy diffs. Please remove the whitespace so the line is truly empty.
    private final JmsProperties jmsProperties;
    
    // Memoized dedicated listener container ConnectionFactory instances to avoid duplicates and enable lifecycle management

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@rujche

rujche commented Jun 30, 2026

Copy link
Copy Markdown
Member Author

/azp run java - spring - tests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

…ed-subclass-of-ServiceBusJmsConnectionFactory-into-the-configuration
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
throw new IllegalStateException("Unable to create JmsConnectionFactory", ex);
}
private ServiceBusJmsConnectionFactory createConnectionFactoryInstance(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep this logic here because the responsibility of the configuration class is simply to create beans, and it doesn't need much other logic. This class is similar to the class in the package path com.azure.spring.cloud.service.implementation.xxx.factory, both are responsible for credential logic, but the difference is that it is stored in the autoconfiguration module.

* </p>
*/
@FunctionalInterface
public interface AzureServiceBusJmsConnectionFactoryFactory {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused about the naming of the dual-factory pattern because there's already a class with the same name suffix, com.azure.spring.cloud.autoconfigure.implementation.jms.ServiceBusJmsConnectionFactoryFactory, but it's an internally used class. Could you change its name to end with "provider" or "supplier"? It would be more developer-friendly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azure-spring All azure-spring related issues azure-spring-servicebus Spring service bus related issues.

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

[FEATURE REQ] Make it possible to inject desired subclass of ServiceBusJmsConnectionFactory into the configuration

3 participants